﻿$(document).ready(function () {

    getClientsByIdUser();


});

function getClientsByIdUser() {

    var userId = 1;

    $.ajax({
        url: '/clientAssign/getClientsByUserSelected?userId=' + userId,
        contentType: 'application/json; charset=utf-8',
        type: 'GET',
        success: function (response, status, error) {
            renderTable(response);
        }
    });
}

function renderTable(jsonData) {

    var table = $('#assign-table tbody').empty();

    $.each(jsonData, function (key, value) {

        var $row = $("<tr> </tr>");

        $row.append("<td>" + value.CompletedName + "</td>");
        $row.append("<td class='text-center'>" + value.Gender + "</td>");
        $row.append("<td>" + value.CreditCard + "</td>");
        $row.append("<td>" + value.Dni + "</td>");
        $row.append("<td>" + value.Address + "</td>");
        $row.append("<td class='text-center'><input type='checkbox' value='" + value.Id + "'/></td>");

        table.append($row);

    });
}

function assignClientToUser() {

    $("#btn-assign").click(function () {

        var checkboxs = $("#assign-table input:checked");
        checkboxsList = new Array();

        $.each(checkboxs, function (key, value) {
            checkboxsList.push($(value).val());
        });

        var json = {
            UserSelected: $("#MySelect option:selected").html(),
            CheckboxsList: checkboxsList
        };

        //$.ajax({
        //    url: '/',
        //    data: JSON.stringify(json),
        //    contentType: 'application/json; charset=utf-8',
        //    type: 'POST',
        //    beforeSend: function () {

        //    },
        //    success: function (data) {

        //    },
        //    error: function (jqXHR, status, error) {

        //        var jsonData = $.parseJSON(jqXHR.responseText);

        //        $.each(jsonData, function (key, value) {

        //        });

        //    },
        //    complete: function (jqXHR, status) {

        //    }
        //});

    });


   

}